package com.hu.jie.day01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hu.jie.day01.R;
import com.hu.jie.day01.bean.CommentBean;
import com.hu.jie.day01.fragment.TestFragment;
import com.hu.jie.day01.utils.TimeUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * ***********************************************************
 * author: jie
 * time: 2016/7/17 18:09
 * name:
 * overview:Build.VERSION.SDK_INT:版本号
 * usage:
 * *************************************************************
 */
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.TestViewHolder> {

    private Context mContext;
    private List<CommentBean.DataBean.CommentsBean> mDatas;

    public TestAdapter(Context context, List<CommentBean.DataBean.CommentsBean> datas) {
        this.mContext = context;
        this.mDatas = datas;
    }

    @Override
    public TestViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.recy_item, parent, false);
        return new TestViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TestViewHolder holder, int position) {
        CommentBean.DataBean.CommentsBean bean = mDatas.get(position);
        Picasso.with(mContext).load(bean.getUser().getAvatar_url()).into(holder.item_iv);
        holder.item_tv3.setText(bean.getUser().getNickname());
        holder.item_tv2.setText(TimeUtils.getDateToString(bean.getCreated_at()));
        holder.item_tv1.setText(bean.getContent());
    }

    @Override
    public int getItemCount() {
        Log.i("123","--------->!!!------->"+mDatas.size());
        return mDatas == null ? 0 : mDatas.size();
    }

    class TestViewHolder extends RecyclerView.ViewHolder {
        private TextView item_tv1,item_tv2,item_tv3;
        private ImageView item_iv;
        public TestViewHolder(View itemView) {
            super(itemView);
            item_iv = (ImageView) itemView.findViewById(R.id.item_iv);
            item_tv1 = (TextView) itemView.findViewById(R.id.item_tv1);
            item_tv2 = (TextView) itemView.findViewById(R.id.item_tv2);
            item_tv3 = (TextView) itemView.findViewById(R.id.item_tv3);
        }
    }
}
